package com.bo.threadEnd;

/**
 * @Author: gpb
 * @Date: 2024/7/15 22:29
 * @Description:
 */
public class Interrupt {
    public static void main(String[] args) throws InterruptedException {
        // 线程默认情况下interrupt 标记为false
        System.out.println(Thread.currentThread().isInterrupted());
        // 执行interrupt之后，在打印信息
        Thread.currentThread().interrupt();
        // interrupt标记为true
        System.out.println(Thread.currentThread().isInterrupted());
        // 返回当前线程，并清除interrupt标记，标记true
        System.out.println(Thread.interrupted());
        // 归位false
        System.out.println(Thread.interrupted());
        // ==========================
        Thread t = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("Thread is running");
            }
            System.out.println("Thread is stop");
        });
        t.start();
        Thread.sleep(500);
        t.interrupt();
    }
}
